// 设置基础url路径
// const baseUrl='http://localhost:8848/cartoonrabbit/v1/api'
const baseUrl='https://yundong.xunmeng.icu/cartoonrabbit/v1/api'
let http=({//对页面穿过来的参数进行解构
	url,
	method,
	data,
	header,
})=>{
	return new Promise(function(resolve,reject){
		uni.showLoading({
			title:'加载中...'
		})
		uni.request({
			url:baseUrl+url,
			method:method,
			dataType: "json",
			responseType: 'text',
			data: data,  //请求的参数
			withCredentials:true,
			header:header,
			success(res){
				// console.log(res)
				if(res.statusCode==401||res.statusCode==403||res.data.code==401||res.data.code==403){
					uni.showToast({
						title: '授权过期',
						icon: 'none',
						duration: 2000,
						position: 'bottom'
					});
					uni.removeStorageSync('token')
					uni.removeStorageSync('userInfo')
					uni.redirectTo({
						url:'/subpkg/login/login'
					})
				}else{
					resolve(res.data)
				}
			},
			fail(err) {
				reject(err)
			},
			complete(cp){
				uni.hideLoading()
			}
		})
	})
}

export {baseUrl,http}